import Vue from 'vue';

Vue.directive('focus', {
  // 当绑定元素插入到 DOM 中。

  inserted: function (el) {
    // 聚焦元素
    el.focus()
  },

});

Vue.directive('time', {

  inserted: function (el, binding, vnode) {

    let time = binding.value;
    let date = new Date(time);

    let o = {
      Y: date.getFullYear() + '年',
      M: (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '月',
      D: ('0' + date.getDate()).slice(-2) + '日 ',
      h: ('0' + date.getHours()).slice(-2) + ':',
      m: ('0' + date.getMinutes()).slice(-2) + '',
    };

    el.innerHTML = `${o.Y}${o.M}${o.D}${o.h}${o.m}`
  },

});

Vue.directive('time2', {

  inserted: function (el, binding, vnode) {

    let time = binding.value;
    let date = new Date(time);

    let o = {
      Y: date.getFullYear() + '年',
      M: (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '月',
      D: ('0' + date.getDate()).slice(-2) + '日 ',
      h: ('0' + date.getHours()).slice(-2) + ':',
      m: ('0' + date.getMinutes()).slice(-2) + '',
    };

    el.innerHTML = `${o.Y}${o.M}${o.D}${o.h}${o.m}`
  },

});
export {Vue}
